package com.l024.easyandroidlib.dialog.manager;

import android.app.Dialog;
import android.content.Context;
import android.view.Gravity;
import android.view.View;

import com.l024.easyandroidlib.R;
import com.l024.easyandroidlib.dialog.view.DialogView;

/**
 * @author wu_ming_zhi_bei
 * @date 2020/2/26 11:46
 * @Notes 提示框管理类
 */
public class DialogManager {
    private static volatile DialogManager mInstance = null;

    private DialogManager() {

    }

    public static DialogManager getInstance() {
        if (mInstance == null) {
            synchronized (DialogManager.class) {
                if (mInstance == null) {
                    mInstance = new DialogManager();
                }
            }
        }
        return mInstance;
    }

    public DialogView initView(Context mContext, int layout) {
        return new DialogView(mContext, layout, R.style.Theme_Dialog, Gravity.CENTER);
    }

    public DialogView initView(Context mContext, int layout, int gravity) {
        return new DialogView(mContext, layout, R.style.Theme_Dialog, gravity);
    }

    public DialogView initView(Context mContext, int layout, View view) {
        return new DialogView(mContext, layout, R.style.Theme_Dialog, view);
    }

    /**
     * 设置弹框点击空白不消失
     * @param dialog
     */
    public void setCancelable(Dialog dialog){
        if (dialog != null) {
            dialog.setCancelable(false);
        }
    }

    public void show(Dialog dialog) {
        if (dialog != null) {
            if (!dialog.isShowing()) {
                dialog.show();
            }
        }
    }

    public void hide(Dialog dialog) {
        if (dialog != null) {
            if (dialog.isShowing()) {
                dialog.dismiss();
            }
        }
    }

    /**
     * 权限弹窗
     */
    public DialogView getPermissionDialog(Context mContext,int layoutId){
        return initView(mContext,layoutId);
    }

    /**
     * 跳转到设置弹窗
     */
    public DialogView getSettingDialog(Context mContext,int layoutId){
        return initView(mContext,layoutId);
    }
}
